package net.m510.autosurfer.saison;

import java.net.URI;
import java.util.logging.Logger;

import net.m510.autosurfer.common.DocumentGetProcess;
import net.m510.autosurfer.common.exception.InvalidDocumentException;

import org.apache.http.HttpHost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.CloseableHttpClient;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

public class SaisonGoDetail extends DocumentGetProcess {
	private static final Logger log = Logger.getLogger(SaisonGoDetail.class.getName());

	public SaisonGoDetail() {
		this(null,null);
	}
	
	public SaisonGoDetail(CloseableHttpClient client,HttpClientContext context) {
		super(client, context);
		super.log = log;
	}

	@Override
	protected URI getUri(Document doc) {
		Elements e = doc.getElementsByAttributeValue("alt", "利用明細確認");
		if ( e.isEmpty() ) throw new InvalidDocumentException("利用明細確認のURLが見つかりません",doc);
		HttpHost host = context.getTargetHost();
		URI uri = URI.create(host.toURI());
		uri = uri.resolve(e.first().parent().attr("href"));
		return uri;
	}
}
